package behaviours;

import jade.core.AID;
import jade.core.behaviours.SimpleBehaviour;
import jade.domain.DFService;
import jade.domain.FIPAException;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.domain.FIPAAgentManagement.ServiceDescription;

@SuppressWarnings("serial")
public class RegisterServiceBehaviour extends SimpleBehaviour {

	private boolean registered;
	private DFAgentDescription dfd;

	public RegisterServiceBehaviour(AID aid, ServiceDescription[] sds) {
		dfd = new DFAgentDescription();
		dfd.setName(aid);
		for (ServiceDescription sd : sds)
			dfd.addServices(sd);
		registered = false;
	}

	@Override
	public void action() {
		try {
			DFService.register(myAgent, dfd);
			registered = true;
		} catch (FIPAException e) {
			registered = false;
		}
	}

	@Override
	public boolean done() {
		return registered;
	}
}
